#pragma once
#include <string>
#include <cstdint>
#include <mutex>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <string.h>
#include <sys/ioctl.h>

namespace HAL
{
    class Serial
    {
        public:
            enum class StopBits
            {
                One,
                Two
            };
            enum class Parity
            {
                None,
                Odd,
                Even
            };
            enum class DataBits
            {
                Five,
                Six,
                Seven,
                Eight
            };
        public:
            Serial(const std::string &dev, speed_t baud, DataBits dataBits = Serial::DataBits::Eight, Parity parity = Serial::Parity::None, StopBits stopBits =  Serial::StopBits::One );
            ~Serial();
            int ReadBuffer(uint8_t *data, size_t len, std::chrono::milliseconds timeout);
            int WriteBuffer(uint8_t *data, size_t len);
        private:
            std::string dev;
            std::mutex mtx;
            int fd = -1;
    };
}
